<?php
namespace Portal\Api;
//use Portal\Common\Api;
use Portal\Domain\Admin as AdminDomain;
use Admin\Domain\Rights as RightsDomain;

use Portal\Common\DataApi as Api;

/**
 * 权限组件
 */
class Rights extends Api {

    protected function getDataModel() {
        return new \Admin\Model\RightsRBACPolicy();
    }

    // 必须提供的字段
    protected function createDataRequireKeys() {
        return array('class_name', 'role', 'action_name');
    }

    protected function updateDataRequireKeys() {
        return array('class_name', 'role', 'action_name');
    }

    public function updateData() {
        $rs = parent::updateData();
        $this->refreshPolicyCsv();
        return $rs;
    }

    public function createData() {
        $rs = parent::createData();
        $this->refreshPolicyCsv();
        return $rs;
    }

    public function deleteData() {
        $rs = parent::deleteData();
        $this->refreshPolicyCsv();
        return $rs;
    }


    ///**
    // * 获取全部权限策略
    // * @desc 获取全部权限策略
    // */
    //public function getAllPolicy() {
    //}

    ///**
    // * 删除权限策略
    // * @desc 删除权限策略
    // */
    //public function removePolicy() {
    //}

    ///**
    // * 添加权限策略
    // * @desc 添加权限策略
    // */
    //public function addPolicy() {
    //}

    ///**
    // * 更新权限策略
    // * @desc 更新权限策略
    // */
    //public function updatePolicy() {
    //}

    /**
     * 更新权限策略
     * @desc 更新权限策略
     */
    public function refreshPolicyCsv() {
        $domain = new RightsDomain();
        $domain->refreshPolicyCsv();
    }
}
